package com.flowable.listener;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.TaskService;
import org.flowable.task.service.delegate.DelegateTask;
import org.flowable.task.service.delegate.TaskListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 长沙先飞信息科技有限公司<br>
 * Created with IntelliJ IDEA.<br>
 * Date:2024/7/19<br>
 * Time:10:11<br>
 * 功能描述：<br>
 *          任务分配监听器
 * @author huang hou chun
 * @since JDK 1.8 <br>
 * Copyright (c) 2023 www.csxfrj.com System Incorporated All Rights Reserved.
 */
@Slf4j
@Component
public class MyListener01 implements TaskListener {

    @Resource
    private TaskService taskService;

    @Override
    public void notify(DelegateTask delegateTask) {
        log.info("MyListener01.notify 执行了... {}", delegateTask.getEventName());
        if (delegateTask.getEventName().equals(EVENTNAME_CREATE)) {
            String assignee = "chunked";
            log.info("指派审批人...{}", assignee);
            // 用户节点的创建 然后指派审批人
            // delegateTask.setAssignee(assignee); 用这个 历史表中审批人还是  NULL
            taskService.setAssignee(delegateTask.getId(), assignee);
        }
    }
}
